﻿namespace WMS6.Web.Configuration
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;

    public class OutboundValidationRuleDetail : BasePage
    {
        protected Button btnCancel;
        protected Button btnSave;
        protected Button btnSaveContinue;
        protected CheckBox chbIsActive;
        protected CheckBox chbRFAssistedPicking;
        protected CheckBox chbRFDirectedPicking;
        protected DropDownList ddlValidationRoutine;
        protected HtmlForm F2208;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdntype;
        protected HtmlInputHidden hdnValidationRuleID;
        protected Label lblAreaDetail;
        protected Label lblLineID;
        protected Label lblMsg;
        protected Label lblValidationRoutine;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtLineID;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Response.Redirect(string.Format("OutboundValidationRule.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnValidationRuleID.Value.Trim())));
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            bool success = false;
            try
            {
                OutboundValidationDetailInfo outboundValidationDetailInfo = new OutboundValidationDetailInfo {
                    ValidationID = this.hdnValidationRuleID.Value,
                    SeqNo = int.Parse(this.txtLineID.Text),
                    RfAssistedPick = this.chbRFAssistedPicking.Checked ? "Y" : "N",
                    RfDirectedPick = this.chbRFDirectedPicking.Checked ? "Y" : "N",
                    ValidationRoutine = this.ddlValidationRoutine.SelectedValue,
                    DynPick = "",
                    IsActive = this.chbIsActive.Checked ? "Y" : "N",
                    CreatedBy = base.UserInfo.UserID
                };
                if (this.hdntype.Value == "edit")
                {
                    outboundValidationDetailInfo.UpdatedBy = base.UserInfo.UserID;
                    if (!string.IsNullOrEmpty(BaseInfoDetailServiceClientProxy.GetInstance().UpdateDetail(outboundValidationDetailInfo, "OUT_BOUND_VALIDATION_DETAIL")))
                    {
                        success = true;
                    }
                }
                else if (!string.IsNullOrEmpty(BaseInfoDetailServiceClientProxy.GetInstance().InsertDetail(outboundValidationDetailInfo, "OUT_BOUND_VALIDATION_DETAIL")))
                {
                    success = true;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2450_005") + ex.Message;
                return;
            }
            if (success)
            {
                base.Response.Redirect(string.Format("OutboundValidationRule.aspx?from={0}&detail={1}&ID={2}", base.UrlEncode(this.hdnFrom.Value), "1", base.UrlEncode(this.hdnValidationRuleID.Value)));
            }
        }

        protected void btnSaveContinue_Click(object sender, EventArgs e)
        {
            bool success = false;
            try
            {
                OutboundValidationDetailInfo outboundValidationDetailInfo = new OutboundValidationDetailInfo {
                    ValidationID = this.hdnValidationRuleID.Value,
                    SeqNo = int.Parse(this.txtLineID.Text),
                    RfAssistedPick = this.chbRFAssistedPicking.Checked ? "Y" : "N",
                    RfDirectedPick = this.chbRFDirectedPicking.Checked ? "Y" : "N",
                    ValidationRoutine = this.ddlValidationRoutine.SelectedValue,
                    DynPick = "",
                    IsActive = this.chbIsActive.Checked ? "Y" : "N",
                    CreatedBy = base.UserInfo.UserID
                };
                if (!string.IsNullOrEmpty(BaseInfoDetailServiceClientProxy.GetInstance().InsertDetail(outboundValidationDetailInfo, "OUT_BOUND_VALIDATION_DETAIL")))
                {
                    success = true;
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = base.GetGlobalMsgResource("F2450_005") + ex.Message;
                return;
            }
            if (success)
            {
                this.lblMsg.Text = this.txtLineID.Text + base.GetGlobalMsgResource("C004");
                this.txtLineID.Text = (int.Parse(this.txtLineID.Text.Trim()) + 10).ToString();
                this.chbRFAssistedPicking.Checked = false;
                this.chbRFDirectedPicking.Checked = false;
                this.chbIsActive.Checked = true;
            }
        }

        protected void btnSaveContinue_Clikc(object sender, EventArgs e)
        {
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlValidationRoutine, "OTValidationRoutine");
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"].ToString()))
            {
                string hdnValidationRuleID = base.Request.QueryString["ID"];
                this.hdnValidationRuleID.Value = hdnValidationRuleID;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"].ToString()))
            {
                string from = base.Request.QueryString["from"];
                this.hdnFrom.Value = from;
            }
            if (!string.IsNullOrEmpty(base.Request.QueryString["SeqNO"].ToString()))
            {
                string LineID = base.Request.QueryString["SeqNO"];
                this.txtLineID.Text = LineID;
            }
            if (base.Request.QueryString["type"] != null)
            {
                this.btnSaveContinue.Enabled = false;
                this.hdntype.Value = base.Request.QueryString["type"];
                this.SetDispatchRuleDetail2From();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetDispatchRuleDetail2From()
        {
            if ((this.hdnValidationRuleID.Value.Trim() != "") && (this.txtLineID.Text.Trim() != ""))
            {
                OutboundValidationDetailInfo outboundValidationDetailInfo = BaseInfoDetailServiceClientProxy.GetInstance().GetDetailInfoByID(this.hdnValidationRuleID.Value.Trim(), this.txtLineID.Text.Trim(), "", "OUT_BOUND_VALIDATION_DETAIL") as OutboundValidationDetailInfo;
                if (outboundValidationDetailInfo != null)
                {
                    this.ddlValidationRoutine.SelectedValue = outboundValidationDetailInfo.ValidationRoutine;
                    this.chbRFAssistedPicking.Checked = outboundValidationDetailInfo.RfAssistedPick == "Y";
                    this.chbRFDirectedPicking.Checked = outboundValidationDetailInfo.RfDirectedPick == "Y";
                    outboundValidationDetailInfo.IsActive = this.chbIsActive.Checked ? "Y" : "N";
                }
            }
        }
    }
}

